//
// Created by wwl on 2021/12/7.
//

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
struct Student{
    int id;
    char name[20];
    float mathScore;
    float computerScore;
};
int StudentScore() {
    struct Student student[5] =
            {
                    {10101,"Zhang",3,3},
                    {10103,"Wang",4,4},
                    {10106,"Li",5,5},
                    {10108,"Ling",2,2},
                    {10110,"Sun",1,1}
            };
    struct Student temp;
    const int n = 5;
    int i,j,k;
    float sum1 = 0,sum2 = 0;
    printf("The order is:\n");
    for(i = 0; i< n;i++){
        k =i;
        sum1 = student[i].mathScore+student[i].computerScore;
        for(j = i+1;j<n;j++){
            sum2 = student[j].mathScore+student[j].computerScore;
            if(sum1 < sum2){
                k = j;
            }
        }
        temp = student[k];student[k] = student[i]; student[i] = temp;
    }
    for(i=0;i<n;i++){
        sum1 = student[i].mathScore+student[i].computerScore;
        printf("%6d %8s %6.2f %6.2f %6.2f\n",student[i].id,student[i].name,student[i].mathScore,student[i].computerScore,sum1);
    }

    return 0;
}
